<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子4-JS进阶（三）</title>
    </head>
    <body>
        <pre>
            <code>
                    // 例子4

                    var url = 'https://hq.tigerbrokers.com/fundamental/finance_calendar/getType/2017-02-26/2017-06-10';
                    var result;

                    var XHR = new XMLHttpRequest();
                    XHR.open('GET', url, true);
                    XHR.send();

                    XHR.onreadystatechange = function() {
                        if (XHR.readyState == 4 && XHR.status == 200) {
                            result = XHR.response;
                            console.log(result);

                            // 伪代码
                            var url2 = 'http:xxx.yyy.com/zzz?ddd=' + result.someParams;
                            var XHR2 = new XMLHttpRequest();
                            XHR2.open('GET', url2, true);
                            XHR2.send();
                            XHR2.onreadystatechange = function() {
                                //...
                            }
                        }
                    }
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/4.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>